home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / dxlib50.zip / MICROSOF.ZIP / EXAMP3.C < prev    next >
C/C++ Source or Header  |  1995-02-11  |  2KB  |  50 lines

  1. /*The following Microsoft C 7.0 program should be linked with the assembly
  2. language library in Example 3.  Combine the library with XLIB.LIB using the
  3. Microsoft LIB utility.  The C program first initializes XLIB.  Next, it
  4. creates a float array.  A control block for SUMARRAY is then constructed
  5. and the call to SUMARRAY is executed.  Finally, the condition code in the
  6. control block is inspected and results are printed.*/
  7.  
  8. #include <stdio.h>
  9. #include <xlib.h>
  10.  
  11. extern unsigned long __far __pascal LINADR(void __far *ptr);
  12. extern void __far __pascal SUMARRAY(void __far *ptr);
  13.  
  14. struct arraydata            /*Structure for passing arguments to SUMARRAY*/
  15. {
  16.   unsigned long condcode;
  17.   unsigned long n;
  18.   unsigned long address;
  19.   float sum;
  20. } ad;
  21.  
  22. void main(void)
  23. {
  24.   unsigned int i;
  25.   unsigned long temp;
  26.   float a[101];
  27.  
  28.   temp = INITXLIB();        /*Initialize XLIB*/
  29.   if (temp != 0)            /*See if an error occurred*/
  30.   {
  31.     printf("Initialization Error:  %lX\n",temp);
  32.     return;
  33.   }
  34.  
  35.   for(i = 0; i <= 100; i++)   /*Initialize a[]*/
  36.     a[i] = i;
  37.  
  38.   ad.condcode = 0;            /*Initialize the condition code*/
  39.   ad.n = 50;                  /*Will sum the first 50 elements in a[]*/
  40.   ad.address = LINADR(a);     /*Compute and record linear address of a[]*/
  41.  
  42.   SUMARRAY(&ad);              /*Sum the array elements*/
  43.   if (ad.condcode != 0)       /*See if an error occurred*/
  44.   {
  45.     printf("Error:  %lX\n",ad.condcode);
  46.     return;
  47.   }
  48.   printf("Sum:  %f\n",ad.sum);   /*The sum should be 1225*/
  49. }
  50.